<template>
<a class="goods-item" href="javascript:" @click.prevent="clickItem(product.id)">
  <img v-lazy="product.cover_url" :alt="product.title">
  <div class="goods-info">
    <div>{{product.title}}</div>
    <div>
      <div class="price"><small>￥</small>{{product.price}}</div>
      <div class="collect"><img src="~assets/images/collect.png">{{product.collects_count}}</div>
    </div>
  </div>
</a>
</template>

<script>
import {useRouter} from 'vue-router'
import {onMounted} from "vue";

export default {
  name: "GoodsLIstItem",
  props: {
    product: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  setup() {
    const router = useRouter()
    const clickItem = id => router.push({
      name: 'Detail',
      params: {
        id
      }
    })
    return {
      clickItem
    }
  }
}
</script>

<style scoped lang="scss">
.goods-item {
  flex-basis: 46%;
  font-size: 12px;
  color: var(--color-text);
  .goods-info > div:first-of-type {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .goods-info > div:last-of-type {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 5px;
    .price {
      color: var(--color-tint)
    }
    .collect {
      margin-left: 5px;
      img {
        width: 12px;
        height: 12px;
        padding-top: 1px;
      }
    }
  }
}
</style>